//
//  CommodityViewController.m
//  BigTyre
//
//  Created by 田涛 on 2017/3/28.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "CommodityViewController.h"
#import "CCommodityViewController.h"
#import "CDetailViewController.h"
#import "CEvaluateViewController.h"
#import "Common.h"

#import "FlipTableView.h"
#import "SegmentTapView.h"

@interface CommodityViewController () <SegmentTapViewDelegate,FlipTableViewDelegate>
@property (nonatomic, strong) FlipTableView *flipView;
@property (nonatomic, strong) SegmentTapView *segmentView;
@end

@implementation CommodityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.self.edgesForExtendedLayout = UIRectEdgeNone;
    [self initSegment];
    [self initFlipTableView];
}

- (void)initSegment {
    _segmentView = [[SegmentTapView alloc] initWithFrame:CGRectMake(0, 0,WIDTH - 200, 30) withDataArray:[NSArray arrayWithObjects:@"商品",@"详情",@"评价", nil] withFont:16];
    _segmentView.delegate = self;
    self.navigationItem.titleView = self.segmentView;
}

- (void)initFlipTableView {
    
    CCommodityViewController *comVC = [[CCommodityViewController alloc] init];
    comVC.sid = self.sid;
    CDetailViewController *detailVC = [[CDetailViewController alloc] init];
    detailVC.sid = self.sid;
    CEvaluateViewController *evaluateVC = [[CEvaluateViewController alloc] init];
    evaluateVC.sid = self.sid;
    
    _flipView = [[FlipTableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-30) withArray:@[comVC,detailVC,evaluateVC]];
    _flipView.delegate = self;
    [self.view addSubview:self.flipView];
}

#pragma mark - SegmentTapViewDelegate
- (void)selectedIndex:(NSInteger)index {
    [self.flipView selectIndex:index];
    NSLog(@"%ld",index);
}

#pragma mark - FlipTableViewDelegate
-(void)scrollChangeToIndex:(NSInteger)index {
    [self.segmentView selectIndex:index];
}

@end
